#!/usr/bin/env/python3.7
# -*- coding: utf-8 -*-

"""
@File    : upload_audio.py
@Time    : 12/01/2021
@Author  : Silence
@Version : 1.0
@Contact : silence2021silence@163.com
@License : (C)Copyright 2021-2021, Silence
@Desc    : None
"""

import pymysql
import datetime

database = pymysql.connect(host="120.24.51.156", user="dormitory_system", password="123456",
                                    database="dormitory_system", charset="utf8")

class Sensor_Data():
    pass

class Audio_Data():
    def upload():
        cursor_1 = database.cursor(cursor=pymysql.cursors.DictCursor)
        with open("./upload_audio/temp.wav", "rb") as f:
            audio_file_bytes = f.read()
        datetime_now = datetime.datetime.now().replace(microsecond=0)
        sql_1 = """
                INSERT INTO `dormitory_system`.`student_audio_message` (
	                `id`, `student_number`, `name`, `room`, 
	                `grade`, `class`, `upload_datetime`, 
	                `audio_file_name`,  `audio_file_data`, 
	                `audio_file_type`, `ip_address` 
                ) 
                VALUES 
	                (
		                %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s
	                )
                        """
        cursor_1.execute(sql_1, ('NULL', '10003', '张三', '102', '高三', '2班', str(datetime_now),
                                 'temp', audio_file_bytes, 'wav', '192.168.8.102'))
        database.commit()
        cursor_1.close()
        database.close()



if __name__ == '__main__':
    Audio_Data.upload()